from flask_login import UserMixin
from routes.app import db
from sqlalchemy import Integer,BLOB,TIMESTAMP
from sqlalchemy.orm import relationship, Mapped,mapped_column
from datetime import datetime
from routes.app import login_manager,db
from sqlalchemy.sql import func
from routes.app import app


@login_manager.user_loader
def load_user(uid):
    return db.session.query(User).get(int(uid))
class User(db.Model,UserMixin):
    __tablename__ = 'user'
    uid = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(32), nullable=False)
    created_at = db.Column(db.DateTime, server_default=db.func.now())
    updated_at = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now())

    def get_id(self):
        return self.uid
    def getUsername(self):
        return self.username
    def getPassword(self):
        return self.password
    def getCreatedAt(self):
        return self.created_at
    def getUpdatedAt(self):
        return self.updated_at
    def check_password_correction(self, attempted_password):
        return self.password==attempted_password

